import request from './request.js'
export default {
  install (Vue, options) {
    // 具体4种方式，写在此处
    Vue.prototype.redirect = function (url) {
      this.router.push('/' + url)
    }
    Vue.prototype.reload = function (url) {
      window.location.replace('http://www.linkphp.com/' + url)
    }
    Vue.prototype.isLogin = function (callback) {
      request.get('/index.php/main/auth/isLogin')
        .then(function (response) {
          if (typeof callback === 'function') {
            callback(response)
          }
        })
        .catch(function (error) {
          if (typeof callback === 'function') {
            callback(error)
          }
        })
    }
    Vue.prototype.wordLimit = function (input) {
      let maxwidth = 200
      if (input.length > maxwidth) {
        return input.substring(0, maxwidth)
      } else {
        return input
      }
    }
  }
}
